package com.zjcode.cdcer.controller;

import com.chinatechstar.component.commons.controller.BaseController;
import com.chinatechstar.component.commons.supports.PageData;
import com.zjcode.cdcer.model.basic.JsonObj;
import com.zjcode.cdcer.service.AnnualReportSummaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ZQM
 * @date 2023/10/12 15:36
 */
@RestController
@RequestMapping("/v1/annualReportSummary")
public class AnnualReportSummaryController extends BaseController {

    @Autowired
    private AnnualReportSummaryService annualReportSummaryService;

    /**
     * 年报总结添加
     */
    @PostMapping("/add")
    public JsonObj add() {
        return annualReportSummaryService.add(getPageData());
    }

    /**
     * 年报总结查看（单个）
     */
    @GetMapping("/selById")
    public JsonObj selById() {
        PageData pageData = getPageData();
        String id = (String) pageData.get("id");
        return annualReportSummaryService.selById(id);
    }

    /**
     * 年报总结查看（列表）
     */
    @PostMapping("/selList")
    public JsonObj selList() {
        return annualReportSummaryService.selList(getPageData());
    }

    /**
     * 年报总结删除
     */
    @GetMapping("/del")
    public JsonObj del() {
        PageData pageData = getPageData();
        String id = (String) pageData.get("id");
        return annualReportSummaryService.del(id);
    }

    /**
     * 展示界面（根据当前登录用户所属机构）
     */
    @GetMapping("/showAllFile")
    public JsonObj showAllFile() {
        PageData pageData = getPageData();
        Long userId = Long.valueOf(pageData.get("user").toString());
        Integer type = Integer.valueOf(pageData.get("type").toString());
        String screeningYear = pageData.get("screeningYear") == null ? null : pageData.get("screeningYear").toString();
        return annualReportSummaryService.showAllFile(userId, type, screeningYear);
    }
}
